#include "StdAfx.h"
#include "InsertStruct.h"


InsertStruct::InsertStruct(void)
{
	state1 = Empty;
	state2 = Empty;
	data1 = new std::vector<double>[9];
	data2 = new std::vector<double>[9];
	allend = false;
}


InsertStruct::~InsertStruct(void)
{
	delete[] data1;
	delete[] data2;
}

bool InsertStruct::GetEmptyAndWrite( std::string *&pSrid, std::vector<double> *&pData )
{
	if (state1 == Empty)
	{
		state1 = Writing;
		pSrid = &srid1;
		pData = data1;
		return true;
	}
	if (state2 == Empty)
	{
		state2 = Writing;
		pSrid = &srid2;
		pData = data2;
		return true;
	}
	return false;
}

bool InsertStruct::GetFullAndRead( std::string *&pSrid, std::vector<double> *&pData )
{
	if (state1 == Full)
	{
		state1 = Reading;
		pSrid = &srid1;
		pData = data1;
		return true;
	}
	if (state2 == Full)
	{
		state2 = Reading;
		pSrid = &srid2;
		pData = data2;
		return true;
	}
	return false;
}

bool InsertStruct::EndWriting()
{
	if (state1 == Writing)
	{
		state1 = Full;
		return true;
	}
	if (state2 == Writing)
	{
		state2 = Full;
		return true;
	}
	return false;
}

bool InsertStruct::EndReading()
{
	if (state1 == Reading)
	{
		srid1.clear();
		for (int i = 0;i<9;i++)
		{
			data1[i].clear();
		}
		state1 = Empty;
		return true;
	}
	if (state2 == Reading)
	{
		srid2.clear();
		for (int i = 0;i<9;i++)
		{
			data2[i].clear();
		}
		state2 = Empty;
		return true;
	}
	return false;

}

void InsertStruct::SetAllEnd()
{
	allend = true;
}

bool InsertStruct::AllEnd()
{
	return allend;
}

